package nl.haemers.data.reflection 
{
	import flash.utils.Dictionary;
	import nl.haemers.data.collections.List;
	import nl.haemers.data.constants.ReflectionConstants;
	import nl.haemers.data.reflection.IVariable;
	import nl.haemers.data.reflection.Variable;
	/**
	 * ...
	 * @author Jonathan Haemers
	 */
	public class Variables implements IVariables 
	{
		private var _list							:List;
		
		public function Variables(description:XML) 
		{
			_list = new List();
			init(description);
		}
		
		/** Public methods **/
		public function getVariable(name:String) : IVariable
		{
			return _list.search(name) as IVariable;
		}
		
		public function hasVariable(name:String) : Boolean
		{
			return _list.hasKey(name);
		}
		
		public function getVariables() : Dictionary
		{
			return _list.items;
		}
		
		/** Internal methods **/
		private function addVariable(name:String, variable:Variable) : Boolean
		{
			return _list.add(name, variable);
		}
		
		/** Static methods**/
		private function init(xml:XML) : Boolean//Variables
		{
			//var variables:Variables = new Variables();
			
			for each(var node:XML in xml.elements(ReflectionConstants.XML_VARIABLE))
			{
				var variable:Variable = new Variable(node);//Variable.init(node) as Variable;
				
				//variables.addVariable(variable.toString(), variable);
				_list.add(variable.name, variable);
				//variables.add(variable.toString(), variable);
			}
			
			return true;
			//return variables;
		}
		
		/** Getters & Setters **/
		
		/** Protected methods **/
		
		/** Private methods **/
		
	}

}